\<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>

<script type="text/javascript" src="${basePath}/static/publics/assets/layer/layer.js"></script>
<link href="${basePath}/static/layer/layer_defined.css" rel="stylesheet" type="text/css">
<link href="${basePath}/static/css/medicalRecord_Search/FilePicture_Manage.css" rel="stylesheet" type="text/css">
<style>
	#headerUl li{}
</style>
<div class="file_manage">
    <div class="file_title">
        <h3>病案查询&gt;图片管理</h3>
        <ul id="headerUl" style="width:220px;">
        	<!-- <li><a>保存</a></li> -->
        	 <li><a onclick="pagination()" id="closeBtn2">编页</a></li>
        	 <input type="checkbox" class="check_cl"  id="checkAll" style="display:inline-block;float:left"/>
        	 <li><a onclick="deleteImgs()" id="closeBtn2">勾选删除</a></li>
           
           
           <!--   <li><a onclick="custom_close()" id="closeBtn2">编页</a></li> -->
        </ul>
    </div>
    <div class="file_content">
        <div class="file_header">
            <div class="left">文件信息</div><div class="right">文件总数：<span id="totalPage">${count}</span><span>个</span></div>
        </div>
        <div class="filePage" id="filepage">
            <ul>
            	<input type="hidden" value="${firstGuid}" id="firstGuid"/>
            	<c:forEach var="scanFile" items="${scanFiles }" varStatus="status">
            		<li data-filename="${status.index +1}" filehash="${scanFile.fileHash}" firstguid="${param.firstGuid }">
            			<img width="100%" height="100%" src="${hospitalizationNoteResourceUrl}${scanFile.fileUrl}${scanFile.fileName}" alt="">
	                	<span class="del" title="删除该图片">X</span>
	                	<input type="checkbox" style="display:inline-block;position:absolute;top:1%;right:5%" class="check_cl noPushMedical"/>
	                </li>
            	</c:forEach>
            </ul>
            
        </div>
    </div>
    <div class="file_table">
    	<c:if test="${not empty hospitalizationNotes }">
    	<p class="line">姓　名: <span>${hospitalizationNotes[0].name}</span></p>
    	<p class="line">身份证号: <span>${hospitalizationNotes[0].id_number}</span></p>
        <p class="line">ID号: <span id="uploadMrId">${hospitalizationNotes[0].mr_id}</span></p>
        <p class="line">出院日期: <span><fmt:formatDate value="${hospitalizationNotes[0].out_hospital_date}" pattern="yyyy-MM-dd"/></span></p>
        <p class="line">就诊类型: <span>${hospitalizationNotes[0].treatment_type_name}</span></p>
        <p class="line">住院次数: <span id="uploadVisitNumber">${hospitalizationNotes[0].visit_number}</span></p>
       	<input type="hidden" id="uploadFirstGuid" value="${hospitalizationNotes[0].first_level_medical_guid}">
        <form action="${basePath}/medrecord/uploadFilesByFirstGuid" method="post"  enctype="multipart/form-data" onsubmit="return validatation()">
        <input type="hidden" name="firstGuid" value="${param.firstGuid }" />
	        <p class="button">
	            <label for="uploadFile">添加文件</label>
	            <input type="file" id="uploadFile" onchange="Addfile()" name="files" style="display:none" multiple />
	            <input style="background: #009388;height:30px;line-height:30px;margin:5px 0 5px 140px;" type="submit" id="submitBtn" class="int" value="上传"/>
	        </p>

	        <p class="button">
	            <span id="files" style="display:none">已选择<i id="total"></i>个文件</span>
	        </p>
        </form>
        </c:if>
    </div>
</div>
<script type="text/javascript" src="${basePath}/static/js/util.js"></script>
<script>
	function validatation(){ 
		var file = document.getElementById('uploadFile'); 
  		if(file.value == ""){
  			alert("请选择要上传的文件夹！");
   			return false;
	   	}
	   	else{
	   		return true; 
	   	} 
	}
    $(function(){
        //删除图片事件
        $(".del").on("click",function(){
            if(confirm("确定删除此图片吗？")) {
            	var liObj = $(this).parents("li");
            	var firstguid = liObj.attr("firstguid");
            	var filehash = liObj.attr("filehash");
            	$.ajax({
					type:"post",
					url:"${basePath}/medrecord/removeMedrecordImage",
					data:{firstGuid:firstguid,fileHash:filehash},
					success:function(data){
						if(data!=null && data.success == true){
							liObj.remove();
							$("#totalPage").html(data.data);
						}else{
							alert("删除失败！");
						}
					}
				}); 
            	
                
            }
        });

    });
    //增加文件
   function Addfile(){
       var files=$("#uploadFile").get(0).files;
       var length=files.length;
       $("#total").html(length);
       $("#files").css("display","block");
   }
    
    
 //选择所有或取消选择所有
	$("#checkAll").click(function() {
		if ($(this).is(":checked")) {
			$(".noPushMedical").each(function(index) {
				$(this).prop("checked", true);
			});
		} else {
			$(".noPushMedical").each(function(index) {
				$(this).prop("checked", false);
			});
		}
	});
    
    
    function pagination(){
    	var mrId = $("#uploadMrId").html();
    	var visitNumber = $("#uploadVisitNumber").html();
    	var firstGuid = $("#uploadFirstGuid").val();
    	window.location.href="${basePath}/medrecord/paginationMedrecordImages?firstGuid="+firstGuid+"&mrId="+mrId+"&visitNumber="+visitNumber+"";
    }
    
    function deleteImgs(obj){
    	var arr = [];
    	$(".noPushMedical:checked").each(function(index) {
			var fileHash = $(this).parent("li").attr("filehash");
			arr.push(fileHash);
		});
    	if(arr==null || arr.length==0){
    		 layer.alert('请选择删除图片信息后,再继续操作!',{icon:1});
    		 return;
    	}
    	
    layer.confirm("您确认删除选中的图片吗?请确认!", {
        btn : [ '确认', '取消' ]//按钮
    }, function(index) {
    	var firstGuid = $("#firstGuid").val();
    
    	
    	$.ajax({
    		type:"post",
    		data:{fileHashs:arr.toString(),firstGuid:firstGuid},
    		url:"${basePath}/medrecord/removeMedrecordImageList",
    		success:function(data){
    			if(data.success){
    				window.location.href="${basePath}/medrecord/manageMedrecordImage?firstGuid="+firstGuid+""
    			}
    		}
    	});
    }); 

}
</script>
